package com.foreveross.proxyip.local;

import java.util.HashMap;
import java.util.Map;

/**
 * 代理ip池管理
 * @author xiangsf 2013-3-19
 *
 */
public class ProxyIpPoolsManager {

	private Map<String, ProxyIpSimplePool> pools = null;
	private static ProxyIpPoolsManager _instance = null;

	private ProxyIpPoolsManager(){
		pools = new HashMap<String, ProxyIpSimplePool>();
	}

	public static ProxyIpPoolsManager getInstanceManager(){
		if(_instance == null){
			_instance = new ProxyIpPoolsManager();
		}

		return _instance;
	}

	//所有IP 
	public synchronized ProxyIpSimplePool getDefaultSimplePool(){
		ProxyIpSimplePool pool =  pools.get(ProxyIpSimplePool.DEFAULT_PROXY_POOL_INSTANCEID);
		if(pool == null){
			pool = new ProxyIpSimplePool(ProxyIpSimplePool.DEFAULT_PROXY_POOL_INSTANCEID);
			pools.put(ProxyIpSimplePool.DEFAULT_PROXY_POOL_INSTANCEID, pool);
		}
		return pool;
	}

	/**
	 * 获取一个国际IP池。luoml
	 */
	public synchronized ProxyIpSimplePool getInterSimplePool(){
		ProxyIpSimplePool pool =  pools.get(ProxyIpSimplePool.INTER_PROXY_POOL_INSTANCEID);
		if(pool == null){
			pool = new ProxyIpSimplePool(ProxyIpSimplePool.INTER_PROXY_POOL_INSTANCEID);
			pools.put(ProxyIpSimplePool.INTER_PROXY_POOL_INSTANCEID, pool);
		}
		return pool;
	}

	public synchronized ProxyIpRmiChannelPool getRmiChannelPool(){
		ProxyIpSimplePool pool =  pools.get(ProxyIpRmiChannelPool.DEFAULT_PROXY_POOL_INSTANCEID);
		if(pool == null){
			pool = new ProxyIpRmiChannelPool(ProxyIpRmiChannelPool.DEFAULT_PROXY_POOL_INSTANCEID);
			pools.put(ProxyIpRmiChannelPool.DEFAULT_PROXY_POOL_INSTANCEID, pool);
		}
		return (ProxyIpRmiChannelPool)pool;
	}
}